package top.tagao.m03_beHavioralPatterns.b_13chain.middleware;

import top.tagao.m03_beHavioralPatterns.b_13chain.server.Server;

/**
 * 检查用户登录信息
 * @author Viktor.Liu
 * @Date 2023/4/28 17:34
 */
public class UserExistsMiddleWare extends MiddleWare {

    private Server server;

    public UserExistsMiddleWare(Server server) {
        this.server = server;
    }


    @Override
    public boolean handle(String email, String password) {
        if (!server.hasEmail(email)) {
            System.out.println("This email is not registered!");
            return false;
        }
        if (!server.isValidPassword(email, password)) {
            System.out.println("Wrong password!");
            return false;
        }
        return handleNext(email,password);
    }


}
